/* ==================================================================
* Copyright (c) 2024/11/15 SCNU LiuJunJie z-ken
* All rights reserved.
* fileName:	util.h
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the xxx Group. and
* its contributors.
* 4. Neither the name of the Group nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Author,GROUP AND CONTRIBUTORS
* ===================================================================
* Author: LiuJunJie z-ken.
*/

//
// Created by zken on 2024/11/4.
//
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;
#ifndef PROJECTLIZE_UTIL_H
#define PROJECTLIZE_UTIL_H


class util {
public:
    static string stackToString(stack<string> s, int reverse1 = false) {
        string res = "";
        vector<string> v;
        // 拷贝
        stack<string> t = stack<string>(s);
        while (!t.empty()) {
            string s_t = t.top();
            t.pop();
            v.push_back(s_t);
        }
        if (reverse1) {
            reverse(v.begin(), v.end());
        }
        for (const string &vi: v) {
            res = res + (vi);
            res += ",";
        }

        return res;
    }

    static string stackToString(stack<int> s, int reverse1 = false) {
        string res = "";
        vector<string> v;
        // 拷贝
        stack<int> t = stack<int>(s);
        while (!t.empty()) {
            // int转字符串
            string s_t = to_string(t.top());
            t.pop();
            v.push_back(s_t);
        }
        if (reverse1) {
            reverse(v.begin(), v.end());
        }
        for (const string &vi: v) {
            res = res + (vi);
            res += ",";
        }
        return res;
    }

    static string queueToString(queue<string> q) {
        string res = "";
        queue<string> t = queue<string>(q);
        while (!t.empty()) {
            string i = t.front();
            t.pop();
            res = res + i;
            res += ",";
        }
        return res;
    }

    static string getSubstringAfterChar(char c, const string &str) {
        int pos = str.find(c);
        string ret;
        int sLen = str.size();
        if (pos != string::npos) {
            ret = str.substr(pos + 1, sLen - pos);
        }
        return ret;
    }

    static string getSubstringBeforeChar(char c, const string &str) {
        int pos = str.find(c);
        string ret = str;
        if (pos != string::npos) {
            ret = str.substr(0, pos - 1);
        }
        return ret;
    }

    /**
     * 判断是否为数字
     * @param str
     * @return
     */
    static bool isNumber(const std::string &str) {
        if (str.empty() || (!isdigit(str[0]) && str[0] != '-' && str[0] != '+')) {
            return false;
        }
        return std::all_of(str.begin(), str.end(),
                           [](char c) { return std::isdigit(c) || c == '.' || c == 'e' || c == 'E'; });
    }

};


#endif //PROJECTLIZE_UTIL_H
